<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Ucenik filter form base class.
 *
 * @package    dnevnik
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BaseUcenikFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'skola_id'           => new sfWidgetFormPropelChoice(array('model' => 'Skola', 'add_empty' => true)),
      'razred_id'          => new sfWidgetFormPropelChoice(array('model' => 'Razred', 'add_empty' => true)),
      'roditelj_id'        => new sfWidgetFormPropelChoice(array('model' => 'Roditelj', 'add_empty' => true)),
      'red_br'             => new sfWidgetFormFilterInput(),
      'maticna_kn'         => new sfWidgetFormFilterInput(),
      'delovodni_br'       => new sfWidgetFormFilterInput(),
      'azuriran'           => new sfWidgetFormFilterInput(),
      'datum_rod'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'mesto_rod'          => new sfWidgetFormFilterInput(),
      'opstina_rod'        => new sfWidgetFormFilterInput(),
      'drzava_rod'         => new sfWidgetFormFilterInput(),
      'jmbg'               => new sfWidgetFormFilterInput(),
      'tip'                => new sfWidgetFormFilterInput(),
      'ucenik_razred_list' => new sfWidgetFormPropelChoice(array('model' => 'Razred', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'skola_id'           => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Skola', 'column' => 'id')),
      'razred_id'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Razred', 'column' => 'id')),
      'roditelj_id'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Roditelj', 'column' => 'id')),
      'red_br'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'maticna_kn'         => new sfValidatorPass(array('required' => false)),
      'delovodni_br'       => new sfValidatorPass(array('required' => false)),
      'azuriran'           => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'datum_rod'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'mesto_rod'          => new sfValidatorPass(array('required' => false)),
      'opstina_rod'        => new sfValidatorPass(array('required' => false)),
      'drzava_rod'         => new sfValidatorPass(array('required' => false)),
      'jmbg'               => new sfValidatorPass(array('required' => false)),
      'tip'                => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'ucenik_razred_list' => new sfValidatorPropelChoice(array('model' => 'Razred', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('ucenik_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addUcenikRazredListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(UcenikRazredPeer::UCENIK_ID, UcenikPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(UcenikRazredPeer::RAZRED_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(UcenikRazredPeer::RAZRED_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Ucenik';
  }

  public function getFields()
  {
    return array(
      'id'                 => 'ForeignKey',
      'skola_id'           => 'ForeignKey',
      'razred_id'          => 'ForeignKey',
      'roditelj_id'        => 'ForeignKey',
      'red_br'             => 'Number',
      'maticna_kn'         => 'Text',
      'delovodni_br'       => 'Text',
      'azuriran'           => 'Number',
      'datum_rod'          => 'Date',
      'mesto_rod'          => 'Text',
      'opstina_rod'        => 'Text',
      'drzava_rod'         => 'Text',
      'jmbg'               => 'Text',
      'tip'                => 'Number',
      'ucenik_razred_list' => 'ManyKey',
    );
  }
}
